package fun.yaozun.study.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: yaozun
 * @Date: 2018/4/12 0012 09:48
 * @Description:
 */
public class TimeUtil {
    /**
     * 时间戳转Date
     * @param time
     * @param format
     * @return
     */
    public static Date LongToDate(Long time,SimpleDateFormat format){
        if (time==null){return null;}
        Date timeDate = null;
        String timeStr = format.format(time);
        if (timeStr!=""&&timeStr!=null){
            try {
                timeDate = format.parse(timeStr);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return timeDate;
    }

    /**
     *
     * @param time
     * @param format
     * @return
     */
    public static Long StringToLong(String time,SimpleDateFormat format){
        if (time==""||time==null){return 0L;}
        Date dateTime = null;
        long longTime = 0;
        try {
            dateTime = format.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        longTime = dateTime.getTime();
        return longTime;
    }

    /**
     * 字符串时间转Date
     * @param time
     * @param format
     * @return
     */
    public static Date StringToDate(String time,SimpleDateFormat format){

        return null;
    }
}
